package com.eastfair.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.home.dto.*;
import com.eastfair.home.entity.VenueReportDrawing;
import com.eastfair.home.service.VenueReportDrawingService;
import com.eastfair.home.vo.VenueReportDrawingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 一键报馆图纸
 * </p>
 *
 * @author dq
 * @date 2022-10-31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/venueReportDrawing")
@Api(value = "VenueReportDrawing", tags = "一键报馆图纸")
@PreAuth(replace = "home:venueReportDrawing:")
public class VenueReportDrawingController extends SuperController<VenueReportDrawingService, Long, VenueReportDrawing, VenueReportDrawingPageQuery, VenueReportDrawingSaveDTO, VenueReportDrawingUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private VenueReportDrawingService venueReportDrawingService;

    @Override
    public void handlerResult(IPage<VenueReportDrawing> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<VenueReportDrawing> venueReportDrawingList = list
                .stream()
                .map((map) -> VenueReportDrawing.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(venueReportDrawingList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<VenueReportDrawingPageQuery> params) {
        VenueReportDrawingPageQuery pageQuery = params.getModel();
    }

    /**
     * 查询图纸列表VO.
     *
     * @param param the param
     * @return the r
     */
    @ApiOperation("查询图纸列表VO")
    @PostMapping("/query/venueReportDrawing")
    public R<List<VenueReportDrawingVO>> queryVenueReportDrawing(@RequestBody VenueReportDrawingDTO param) {
        log.info("queryVenueReportDrawing - 查询图纸列表VO, param={}", param);
        return R.successDef(venueReportDrawingService.listVenueReportDrawingVO(param));
    }

    /**
     * 提交报馆图纸.
     *
     * @param venueReportDrawingCategoryDTO the list
     * @return the r
     */
    @ApiOperation("提交报馆图纸")
    @SysLog("提交报馆图纸")
    @PostMapping("/submitBatch")
    public R<Boolean> submitBatch(@RequestBody VenueReportDrawingCategoryDTO venueReportDrawingCategoryDTO) {
        log.info("submitBatch - 提交报馆图纸, venueReportDrawingCategoryDTO={}", venueReportDrawingCategoryDTO);
        return R.successDef(venueReportDrawingService.submitBatch(venueReportDrawingCategoryDTO));
    }
}
